﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace Gw2Api
{

    public class Objective
    {
        public enum ObjectiveType
        {
            Camp,
            Tower,
            Keep,
            Castle,
            Ruins,
            Generic,
            Resource,
            Spawn,
        }

        public string id;
        public string name;
        public int sector_id;
        public ObjectiveType type;
        public WvWMaps map_type;
        public int map_id;
        public int upgrade_id;
        public string tag;
    }

    public class ObjectiveApi : BaseApi
    {
        public List<Objective> objectives;

        Dictionary<string, string> _objectiveTags = new Dictionary<string,string>();

        public ObjectiveApi()
        {
            SetupObjectiveTags();

            LoadObjectives();
        }

        private void SetupObjectiveTags()
        {
            #region Objective Tags
            #region Eternal Battlegrounds
            _objectiveTags["38-1"] = "EB-R-Keep"; // Overlook
            _objectiveTags["38-2"] = "EB-B-Keep"; // Valley
            _objectiveTags["38-3"] = "EB-G-Keep"; // Lowlands
            _objectiveTags["38-4"] = "EB-B-1-Camp"; // Golanta Clearing
            _objectiveTags["38-5"] = "EB-R-2-Camp"; // Pangloss Rise
            _objectiveTags["38-6"] = "EB-R-1-Camp"; // Speldan Clearcut
            _objectiveTags["38-7"] = "EB-G-2-Camp"; // Danelon Passage
            _objectiveTags["38-8"] = "EB-G-1-Camp"; // Umberglade Woods
            _objectiveTags["38-9"] = "EB-C-Castle"; // Stonemist Castle
            _objectiveTags["38-10"] = "EB-B-2-Camp"; // Rogue’s Quarry
            _objectiveTags["38-11"] = "EB-G-3-Tower"; // Aldon’s Ledge
            _objectiveTags["38-12"] = "EB-G-4-Tower"; // Wildcreek Run
            _objectiveTags["38-13"] = "EB-G-2-Tower"; // Jerrifer’s Slough
            _objectiveTags["38-14"] = "EB-G-1-Tower"; // Klovan Gully
            _objectiveTags["38-15"] = "EB-B-3-Tower"; // Langor Gulch
            _objectiveTags["38-16"] = "EB-B-4-Tower"; // Quentin Lake
            _objectiveTags["38-17"] = "EB-R-2-Tower"; // Mendon’s Gap
            _objectiveTags["38-18"] = "EB-R-1-Tower"; // Anzalias Pass
            _objectiveTags["38-19"] = "EB-R-4-Tower"; // Ogrewatch Cut
            _objectiveTags["38-20"] = "EB-R-3-Tower"; // Veloka Slope
            _objectiveTags["38-21"] = "EB-B-1-Tower"; // Durios Gulch
            _objectiveTags["38-22"] = "EB-B-2-Tower"; // Bravost Escarpment
            #endregion
            #region Old Alpine Borderlands
            //_objectiveTags["96-23"] = "BL-C-Keep"; // Garrison
            //_objectiveTags["96-24"] = "BL-S-Camp"; // Champion’s Demense
            //_objectiveTags["96-25"] = "BL-SW-Tower"; // Redbriar
            //_objectiveTags["96-26"] = "BL-SE-Tower"; // Greenlake
            //_objectiveTags["96-27"] = "BL-W-Keep"; // Ascension Bay
            //_objectiveTags["96-28"] = "BL-NE-Tower"; // Dawn’s Eyrie
            //_objectiveTags["96-29"] = "BL-N-Camp"; // The Spiritholme
            //_objectiveTags["96-30"] = "BL-NW-Tower"; // Woodhaven
            //_objectiveTags["96-31"] = "BL-E-Keep"; // Askalion Hills
            //_objectiveTags["94-32"] = "BL-E-Keep"; // Etheron Hills
            //_objectiveTags["94-33"] = "BL-W-Keep"; // Dreaming Bay
            //_objectiveTags["94-34"] = "BL-S-Camp"; // Victor’s Lodge
            //_objectiveTags["94-35"] = "BL-SW-Tower"; // Greenbriar
            //_objectiveTags["94-36"] = "BL-SE-Tower"; // Bluelake
            //_objectiveTags["94-37"] = "BL-C-Keep"; // Garrison
            //_objectiveTags["94-38"] = "BL-NW-Tower"; // Longview
            //_objectiveTags["94-39"] = "BL-N-Camp"; // The Godsword
            //_objectiveTags["94-40"] = "BL-NE-Tower"; // Cliffside
            //_objectiveTags["95-41"] = "BL-E-Keep"; // Shadaran Hills
            //_objectiveTags["95-42"] = "BL-SE-Tower"; // Redlake
            //_objectiveTags["95-43"] = "BL-S-Camp"; // Hero’s Lodge
            //_objectiveTags["95-44"] = "BL-W-Keep"; // Dreadfall Bay
            //_objectiveTags["95-45"] = "BL-SW-Tower"; // Bluebriar
            //_objectiveTags["95-46"] = "BL-C-Keep"; // Garrison
            //_objectiveTags["95-47"] = "BL-NW-Tower"; // Sunnyhill
            //_objectiveTags["95-48"] = "BL-NW-Camp"; // Faithleap
            //_objectiveTags["95-49"] = "BL-SW-Camp"; // Bluevale Refuge
            //_objectiveTags["94-50"] = "BL-SE-Camp"; // Bluewater Lowlands
            //_objectiveTags["94-51"] = "BL-NE-Camp"; // Astralholme
            //_objectiveTags["94-52"] = "BL-NW-Camp"; // Arah’s Hope
            //_objectiveTags["94-53"] = "BL-SW-Camp"; // Greenvale Refuge
            //_objectiveTags["95-54"] = "BL-NE-Camp"; // Foghaven
            //_objectiveTags["95-55"] = "BL-SE-Camp"; // Redwater Lowlands
            //_objectiveTags["95-56"] = "BL-N-Camp"; // The Titanpaw
            //_objectiveTags["95-57"] = "BL-NE-Tower"; // Cragtop
            //_objectiveTags["96-58"] = "BL-NW-Camp"; // Godslore
            //_objectiveTags["96-59"] = "BL-SW-Camp"; // Redvale Refuge
            //_objectiveTags["96-60"] = "BL-NE-Camp"; // Stargrove
            //_objectiveTags["96-61"] = "BL-SE-Camp"; // Greenwater Lowlands
            //_objectiveTags["94-62"] = "BL-S-Ruin"; // Temple of Lost Prayers
            //_objectiveTags["94-63"] = "BL-SW-Ruin"; // Battle's Hollow
            //_objectiveTags["94-64"] = "BL-NW-Ruin"; // Bauer's Estate
            //_objectiveTags["94-65"] = "BL-NE-Ruin"; // Orchard Overlook
            //_objectiveTags["94-66"] = "BL-SE-Ruin"; // Carver's Ascent
            //_objectiveTags["96-67"] = "BL-SE-Ruin"; // Carver's Ascent
            //_objectiveTags["96-68"] = "BL-NE-Ruin"; // Orchard Overlook
            //_objectiveTags["96-69"] = "BL-NW-Ruin"; // Bauer's Estate
            //_objectiveTags["96-70"] = "BL-SW-Ruin"; // Battle's Hollow
            //_objectiveTags["96-71"] = "BL-S-Ruin"; // Temple of Lost Prayers
            //_objectiveTags["95-72"] = "BL-SE-Ruin"; // Carver's Ascent
            //_objectiveTags["95-73"] = "BL-NE-Ruin"; // Orchard Overlook
            //_objectiveTags["95-74"] = "BL-NW-Ruin"; // Bauer's Estate
            //_objectiveTags["95-75"] = "BL-SW-Ruin"; // Battle's Hollow
            //_objectiveTags["95-76"] = "BL-S-Ruin"; // Temple of Lost Prayers
            //_objectiveTags["103"] = "BL-Spawn"; // Spawn
            //_objectiveTags["111"] = "BL-Spawn"; // Spawn
            //_objectiveTags["112"] = "BL-Spawn"; // Spawn
            #endregion
            #region New Alpine Borderlands
            _objectiveTags["32"] = "BL-E-Keep"; // Hills
            _objectiveTags["33"] = "BL-W-Keep"; // Bay
            _objectiveTags["34"] = "BL-S-Camp"; // Lodge/Demesne
            _objectiveTags["35"] = "BL-SW-Tower"; // -briar
            _objectiveTags["36"] = "BL-SE-Tower"; // -lake
            _objectiveTags["37"] = "BL-C-Keep"; // Garrison
            _objectiveTags["38"] = "BL-NW-Tower"; // Longview/Woodhaven/Sunnyhill
            _objectiveTags["39"] = "BL-N-Camp"; // The -
            _objectiveTags["40"] = "BL-NE-Tower"; // Cliffside/Dawn's Eyrie/Cragtop
            _objectiveTags["50"] = "BL-SE-Camp"; // Bluewater Lowlands
            _objectiveTags["51"] = "BL-NE-Camp"; // Astralholme
            _objectiveTags["52"] = "BL-NW-Camp"; // Arah’s Hope/Godslore/Faithleap
            _objectiveTags["53"] = "BL-SW-Camp"; // Refuge
            _objectiveTags["62"] = "BL-S-Ruin"; // Temple of Lost Prayers
            _objectiveTags["63"] = "BL-SW-Ruin"; // Battle's Hollow
            _objectiveTags["64"] = "BL-NW-Ruin"; // Bauer's Estate
            _objectiveTags["65"] = "BL-NE-Ruin"; // Orchard Overlook
            _objectiveTags["66"] = "BL-SE-Ruin"; // Carver's Ascent
            _objectiveTags["103"] = "BL-Spawn"; // Spawn
            _objectiveTags["111"] = "BL-Spawn"; // Spawn
            _objectiveTags["112"] = "BL-Spawn"; // Spawn
            #endregion
            #region Desert Borderlands
            _objectiveTags["99"]  = "BL-N-Camp"; // Lab
            _objectiveTags["100"] = "BL-SE-Camp"; // Farmstead
            _objectiveTags["101"] = "BL-SW-Camp"; // Encampment
            _objectiveTags["102"] = "BL-NW-Tower"; // Academy
            _objectiveTags["104"] = "BL-NE-Tower"; // Necropolis
            _objectiveTags["105"] = "BL-SE-Tower"; // Depot
            _objectiveTags["106"] = "BL-W-Keep"; // Undercroft
            _objectiveTags["107"] = "BL-Spawn"; // Border
            _objectiveTags["108"] = "BL-Spawn"; // Border
            _objectiveTags["109"] = "BL-NE-Camp"; // Refuge
            _objectiveTags["110"] = "BL-SW-Tower"; // Outpost
            _objectiveTags["113"] = "BL-C-Keep"; // Rampart
            _objectiveTags["114"] = "BL-E-Keep"; // Palace
            _objectiveTags["115"] = "BL-NW-Camp"; // Hideaway
            _objectiveTags["116"] = "BL-S-Camp"; // Well
            _objectiveTags["117"] = "BL-Citadel"; // Citadel
            #endregion
            #endregion
        }

        private void LoadObjectives()
        {
            string s = LoadFromUrl(ApiUrls.V2.Objectives);
            objectives = JsonConvert.DeserializeObject<List<Objective>>(s);
            foreach (Objective objective in objectives)
            {
                if (_objectiveTags.ContainsKey(objective.id))
                {
                    objective.tag = _objectiveTags[objective.id];
                }
                else if (_objectiveTags.ContainsKey(objective.id.Split('-')[1]))
                {
                    objective.tag = _objectiveTags[objective.id.Split('-')[1]];
                }
            }
        }
    }
}
